package com.hr.service;

import com.hr.dao.CompanyDAO;
import com.hr.model.Archive;
import com.hr.model.Company;
import com.hr.model.Position;
import com.hr.model.User;
import com.hr.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompanyService
{
    @Autowired
    CompanyDAO companyDAO;

    public Company getCompanyByCId(int cid)
    {
        return companyDAO.getCompanyByCId(cid);
    }

    public List<Company> getCompanysByUser() {
        List<Company> companies=new ArrayList<>();
        Archive archive= AuthUtil.getCurUser().getArchive();

        if(archive!=null)
        {
            List<Position> positions=archive.getPositions();
            for(Position position: positions)
            {
                if(position.getCompany()==null)
                    continue;
                companies.add(position.getCompany());
            }
        }
        return companies;
    }

    public List<Company> getAllCompanys()
    {
        return companyDAO.getAllCompanys();
    }
}
